FUNCTION(extract_version)
    FILE(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/version.h" file_contents)
    STRING(REGEX MATCH "VERSION_MAJOR ([0-9]+)" _  "${file_contents}")
    IF(NOT CMAKE_MATCH_COUNT EQUAL 1)
        MESSAGE(FATAL_ERROR "Could not extract major version number from version.h")
    ENDIF()
    SET(ver_major ${CMAKE_MATCH_1})

    STRING(REGEX MATCH "VERSION_MINOR ([0-9]+)" _  "${file_contents}")
    IF(NOT CMAKE_MATCH_COUNT EQUAL 1)
        MESSAGE(FATAL_ERROR "Could not extract minor version number from version.h")
    ENDIF()
    SET(ver_minor ${CMAKE_MATCH_1})
    STRING(REGEX MATCH "VERSION_BUILD ([0-9]+)" _  "${file_contents}")
    IF(NOT CMAKE_MATCH_COUNT EQUAL 1)
        MESSAGE(FATAL_ERROR "Could not extract build version number from version.h")
    ENDIF()
    SET(ver_build ${CMAKE_MATCH_1})

    SET(PROJECT_VERSION_MAJOR ${ver_major} PARENT_SCOPE)
    SET(PROJECT_VERSION "${ver_major}.${ver_minor}.${ver_build}" PARENT_SCOPE)
ENDFUNCTION()
